import 'dart:async';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:riki_push/enum/phone_platform.dart';
import 'package:riki_push/factory/riki_base_push.dart';
import 'package:riki_base_flutter/riki_base_flutter.dart';

///
///  小米推送
///
class RikiXmPush {
  static const MethodChannel _channel_xm = const MethodChannel('riki_push_xm');

  /// 初始化小米
  static Future<void> init({@required String appId, @required String appKey}) async {
    return await _channel_xm.invokeMethod('init', {
      "appId": appId,
      "appKey": appKey,
    });
  }

  /// 反初始化小米
  static Future<void> unInit({@required String appId, @required String appKey}) async {
    return await _channel_xm.invokeMethod('unInit');
  }

  /// 获取小米regId
  static Future<String> get xmRegId async {
    String regId = '';
    if (Platform.isAndroid && await RikiBasePush.phonePlatform == PhonePlatform.xiaomi) {
      regId = await _channel_xm.invokeMethod('getXmRegId');
      LogUtil.v("小米RegId是" + (regId == null ? 'null' : regId));
    }
    return regId;
  }
}
